<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="/js/jquery.min.js"></script>
    <script>
        function getTest() {
            $.ajaxSetup({
                type: 'get',
                url: 'http://api.hk.com/s/test',
                // 跨域携带Cookie
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                success: function (res) {
                    console.log(res);
                    $("#test").html(res);
                    return false;
                },
                error: function () {
                    alert('请求错误');
                    return false;
                }

            });
            $.ajax();
        }

        function postTest() {
            $.ajaxSetup({
                type: 'post',
                url: 'http://api.hk.com/s/test1',
                // 跨域携带Cookie
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                success: function (res) {
                    console.log(res);
                    $("#test").html(res);
                    return false;
                },
                error: function () {
                    alert('请求错误');
                    return false;
                }

            });
            $.ajax();
        }
    </script>
</head>

<body>
    <button onclick="getTest()">Get</button>
    <button onclick="postTest()">POST</button>
    <p id="test"></p>
</body>

</html>